<template>
  <div class="page-container">
    <pf-table
      ref="pfTable"
      v-model="form"
      :columns="columns"
      :form-items="formItems"
      @get-table-data="getTableData"
    >
      <template #handle="{row}">
        <el-button type="text" size="small" @click="showDetail(row)">详情</el-button>
      </template>
    </pf-table>
  </div>
</template>

<script>
import { PAY_METHOD_LIST, ORDER_TYPE } from '@/utils/enum'
import { getOrderList } from '@/api/order'

export default {
  name: 'OrderList',
  components: {
  },
  data() {
    return {
      payMethodOptions: PAY_METHOD_LIST,
      orderTypeOptions: ORDER_TYPE,
      form: {},
      loading: false
    }
  },
  computed: {
    columns() {
      const attrs = { 'min-width': '150px' }
      return [
        { label: '订单编号', prop: 'orderNo', attrs },
        { label: '订单内容', prop: 'orderDescription', attrs },
        { label: '订单总价', prop: 'amountRealPay', formatter: 'money', attrs },
        { label: '产生时间', prop: 'createTime', attrs },
        { label: '所属商家', prop: 'shopName', attrs },
        { label: '支付方式', prop: 'paymentMethod', attrs },
        { label: '状态', prop: 'orderStatusStr', attrs },
        { label: '操作', slot: 'handle', attrs: { width: '100px', fixed: 'right' }}
      ]
    },
    formItems() {
      return [
        {
          type: 'input',
          label: '所属商家',
          prop: 'shopName'
        },
        {
          type: 'select',
          label: '订单类型',
          prop: 'chargeOfStatus',
          options: this.orderTypeOptions
        }, {
          type: 'select',
          label: '支付方式',
          prop: 'paymentMethod',
          options: this.payMethodOptions,
          attrs: {
            multiple: true
          }
        }, {
          type: 'input',
          label: '订单编号',
          prop: 'orderNo'
        }, {
          type: 'date',
          label: '产生时间',
          prop: 'dateRange',
          attrs: {
            type: 'datetimerange'
          }
        }
      ]
    }
  },

  methods: {

    getTableData({ pageNo, pageSize, ...formQuery }, done) {
      this.loading = true
      const [createStartTime = '', createEndTime = ''] = formQuery?.dateRange || []
      const data = {
        pageNo,
        pageSize,
        createStartTime,
        createEndTime,
        ...formQuery
      }
      getOrderList(data).then(res => {
        this.loading = false
        done({ data: res.data || [], total: res.count || 0 })
      }).catch(() => {
        done({ data: [], total: 0 })
        this.loading = false
      })
    },

    // 详情
    showDetail(row) {
      this.$router.push({
        path: '/order/order/detail',
        query: {
          id: row.id
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped></style>
